import { Controller } from 'egg';

class SettingController extends Controller {
    /**
     * 查找系统设置
     */
    public async searchSetting(){
        const { ctx, ctx: { request } } = this;
        try {
            ctx.validate({
                setting_key:'string'
            }, request.body)
        } catch (e) {
            ctx.body = ctx.helper.responseErrorParam(e.errors[0].message);
            return;
        }
        const result=await this.ctx.service.settingService.searchSetting(request.body);
        ctx.body = ctx.helper.responseSuccess('查找成功',result);
    }

    /**
     * 操作注册状态
     */
    public async settingRegisterStatus(){
        const { ctx, ctx: { request } } = this;
        try {
            ctx.validate({
                setting_key:'string',
                setting_value:'type'
            }, request.body)
        } catch (e) {
            ctx.body = ctx.helper.responseErrorParam(e.errors[0].message);
            return;
        }
        await this.ctx.service.settingService.settingRegisterStatus(request.body);
        ctx.body = ctx.helper.responseSuccess('操作成功');
    }
}
export default SettingController;